<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
    <title>${siteName!""}|学院管理-添加学院</title>
<#include "../common/header.ftl"/>

</head>

<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <aside class="lyear-layout-sidebar">

            <div class="lyear-layout-sidebar-scroll">
        <#include "../common/left-menu.ftl"/>
            </div>

        </aside>
        <!--End 左侧导航-->

    <#include "../common/header-menu.ftl"/>

        <!--页面主要内容-->
        <main class="lyear-layout-content">

            <div class="container-fluid">

                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header"><h4>添加学院</h4></div>
                            <div class="card-body">
                                <form action="add" id="faculties-add-form" method="post" class="row">
                                    <div class="input-group m-b-10">
                                        <span class="input-group-addon">学院编号</span>
                                        <input type="number" onkeyup="value=value.replace(/[^\d]/g,'')" class="form-control required" id="num"
                                               name="num"  placeholder="请输入学院编号" tips="请填写学院编号"/>
                                    </div>
                                    <div class="input-group m-b-10">
                                        <span class="input-group-addon">学院名称</span>
                                        <input type="text" class="form-control required" id="name"
                                               name="name"  placeholder="请输入学院名" tips="请填写学院名"/>
                                    </div>
                                    <div class="input-group m-b-10">
                                        <span class="input-group-addon">学院负责人</span>
                                        <input type="text" class="form-control required" id="leader"
                                               name="leader"  placeholder="请输入学院负责人" tips="请填写学院负责人"/>
                                    </div>
                                    <div class="input-group m-b-10">
                                        <span class="input-group-addon">负责人电话</span>
                                        <input type="text" class="form-control required" id="telephone" onblur="checkPhone()"
                                               name="telephone"  placeholder="请输入负责人电话" tips="请填写负责人电话"/>
                                    </div>
                                    <div class="input-group m-b-10">
                                        <span class="input-group-addon">学院地址</span>
                                        <input type="text" class="form-control required" id="address"
                                               name="address"  placeholder="请输入学院地址" tips="请填写学院地址"/>
                                    </div>
                                    <div class="input-group m-b-10">
                                        <span class="input-group-addon">学院介绍</span>
                                        <input type="text" class="form-control required" id="introduce" name="introduce" tips="请填写学院介绍"/>
                                    </div>
                            </div>

                            <div class="form-group col-md-12">
                                <button type="button" class="btn btn-primary ajax-post" id="add-form-submit-btn">确 定
                                </button>
                                <button type="button" class="btn btn-default"
                                        onclick="javascript:history.back(-1);return false;">返 回
                                </button>
                            </div>
                            </form>

                        </div>
                    </div>
                </div>

            </div>

    </div>

    </main>
    <!--End 页面主要内容-->
</div>
</div>
<#include "../common/footer.ftl"/>
<script type="text/javascript" src="/admin/js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="/admin/js/main.min.js"></script>
<script type="text/javascript">

    function checkPhone(){
        var telephone = document.getElementById('telephone').value;
        var reg = /^1[3456789]\d{9}$/;
        if(!(reg.test(telephone))){
            alert("手机号码有误，请重填");
            $("#telephone").focus();
            return;
        }
    }

    $(document).ready(function () {
        //提交按钮监听事件
        $("#add-form-submit-btn").click(function () {
            if (!checkForm("faculties-add-form")) {
                return;
            }
            var data = $("#faculties-add-form").serialize();
            $.ajax({
                url: 'add',
                type: 'POST',
                data: data,
                dataType: 'json',
                success: function (data) {
                    if (data.code == 0) {
                        showSuccessMsg('学院添加成功!', function () {
                            window.location.href = 'list';
                        })
                    } else {
                        showErrorMsg(data.msg);
                    }
                },
                error: function (data) {
                    alert('网络错误!');
                }
            });
        });
        //监听上传图片按钮
        $("#add-pic-btn").click(function () {
            $("#select-file").click();
        });
    });

</script>
</body>
</html>
